package com.tron.dobest.java.tronnio;


import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class TronFileChannelRead {
    public static void main(String[] args) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(getPath(TronFileChannelRead.class) + "test01.txt");
        FileChannel fileChannel = fileInputStream.getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        fileChannel.read(byteBuffer);
        System.out.println(new String(byteBuffer.array()));
        fileInputStream.close();
    }
    public static String getPath(Class clazz) {
        String pre = "src/main/java/";
        Package aPackage = clazz.getPackage();
        String name = aPackage.getName();
        String newName = pre + name.replaceAll("\\.", "/")+"/";
        return newName;
    }
}
